package com.example.hao.flowercityfm.HFAdapter.ViewHolder;

import android.content.Context;
import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

import com.example.hao.flowercityfm.application.MyApp;
import com.example.hao.flowercityfm.pojo.HomeFragmentData;
import com.example.hao.flowercityfm.utils.HttpUtils;


import java.io.IOException;

import butterknife.ButterKnife;

public abstract class BaseTypeViewHolder extends RecyclerView.ViewHolder {

    protected Context context;

    BaseTypeViewHolder(Context context, View itemView) {
        super(itemView);
        this.context = context;
        ButterKnife.bind(this, itemView);
    }

    public abstract void initView();

    /**
     * 为 ViewHolder 绑定数据
     *
     * @param listBean 数据对象
     */
    public void setData(HomeFragmentData.ListBean listBean) {

    }

    private String json;

    public String getJson() {
        return json;
    }

    private void setJson(String json) {
        this.json = json;

    }

    void loadData(String url) {

        HttpUtils.method2(url, new HttpUtils.OnOkCallBack() {
            @Override
            public void onFailure(@NonNull IOException e) {
                Log.e(MyApp.TAG, "onFailure: " + e.getMessage());
            }

            @Override
            public void onResponse(@NonNull String jsonStr) {
                setJson(jsonStr);
            }
        });

    }


    class ItemDecoration extends RecyclerView.ItemDecoration {
        private int space;

        ItemDecoration(int space) {
            this.space = space;
        }

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            outRect.right = space;
            outRect.left = space;
            outRect.bottom = space;
            outRect.top = space;

        }
    }

}
